package com.rao.crm.service.impl;

import com.rao.crm.dao.SaleVisitDao;
import com.rao.crm.domain.PageBean;
import com.rao.crm.domain.SaleVisit;
import com.rao.crm.service.SaleVisitService;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Srao
 * @version 1.0
 * @className SaleVisitServiceImpl
 * @date 2019/9/21 20:02
 * @package com.rao.crm.service.impl
 * @description
 */
@Transactional
public class SaleVisitServiceImpl implements SaleVisitService {
    @Resource(name = "saleVisitDao")
    private SaleVisitDao saleVisitDao;

    @Override
    public PageBean<SaleVisit> findAll(DetachedCriteria detachedCriteria, Integer currPage, Integer pageSize) {
        Integer totalCount = saleVisitDao.findTotalCount(detachedCriteria);
        PageBean<SaleVisit> pageBean = new PageBean<>(currPage, totalCount, pageSize);
        /*封装的对象*/
        List<SaleVisit> list = saleVisitDao.findAll(detachedCriteria, pageBean.getStartIndex(), pageSize);
        pageBean.setList(list);
        return pageBean;
    }

    @Override
    public void save(SaleVisit saleVisit) {
        saleVisitDao.save(saleVisit);
    }

    @Override
    public void delete(SaleVisit saleVisit) {
        saleVisitDao.delete(saleVisit);
    }

    @Override
    public SaleVisit findById(String visit_id) {
        return saleVisitDao.findById(visit_id);
    }

    @Override
    public void update(SaleVisit saleVisit) {
        saleVisitDao.update(saleVisit);
    }

}
